Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid warning on 32bit #233

Merged
merged 3 commits into from
Jun 12, 2022
Merged

Avoid warning on 32bit #233

merged 3 commits into from
Jun 12, 2022

Conversation

bbonev
Copy link
Member

@bbonev bbonev commented Jun 10, 2022

On 32bit arches where time_t is defined as long int and where
sizeof(long)==sizeof(int), PRI_TIME is PRIu32 which is "u" and gcc warns about
ignoring the long part of the integer type. There is no problem besides the
warning.

Use "lu" in the above conditions and PRIu32 in all other 32bit time_t cases.

udevadm-monitor.c: In function ‘print_device’:
udevadm-monitor.c:49:16: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 3 has type ‘__time_t’ {aka ‘long int’} [-Wformat=]
   49 |         printf("%-6s[%"PRI_TIME".%06ld] %-8s %s (%s)\n",
      |                ^~~~~~~~
   50 |                source,
   51 |                ts.tv_sec, ts.tv_nsec/1000,
      |                ~~~~~~~~~
      |                  |
      |                  __time_t {aka long int}
In file included from ../../src/shared/macro.h:26,
                 from udev.h:26,
                 from udevadm-monitor.c:35:
/usr/include/inttypes.h:104:19: note: format string is defined here
  104 | # define PRIu32  "u"

On 32bit arches where time_t is defined as long int and where
sizeof(long)==sizeof(int), PRI_TIME is PRIu32 which is "u" and gcc warns about
ignoring the long part of the integer type. There is no problem besides the
warning.

Use "lu" in the above conditions and PRIu32 in all other 32bit time_t cases.

udevadm-monitor.c: In function ‘print_device’:
udevadm-monitor.c:49:16: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 3 has type ‘__time_t’ {aka ‘long int’} [-Wformat=]
   49 |         printf("%-6s[%"PRI_TIME".%06ld] %-8s %s (%s)\n",
      |                ^~~~~~~~
   50 |                source,
   51 |                ts.tv_sec, ts.tv_nsec/1000,
      |                ~~~~~~~~~
      |                  |
      |                  __time_t {aka long int}
In file included from ../../src/shared/macro.h:26,
                 from udev.h:26,
                 from udevadm-monitor.c:35:
/usr/include/inttypes.h:104:19: note: format string is defined here
  104 | # define PRIu32  "u"
On 32bit arches where time_t is defined as long int and where
sizeof(long)==sizeof(int), PRI_TIME is PRIu32 which is "u" and gcc warns about
ignoring the long part of the integer type. There is no problem besides the
warning.

Upcast time_t to 64bit and get rid of PRI_TIME and configure checks

udevadm-monitor.c: In function ‘print_device’:
udevadm-monitor.c:49:16: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 3 has type ‘__time_t’ {aka ‘long int’} [-Wformat=]
   49 |         printf("%-6s[%"PRI_TIME".%06ld] %-8s %s (%s)\n",
      |                ^~~~~~~~
   50 |                source,
   51 |                ts.tv_sec, ts.tv_nsec/1000,
      |                ~~~~~~~~~
      |                  |
      |                  __time_t {aka long int}
In file included from ../../src/shared/macro.h:26,
                 from udev.h:26,
                 from udevadm-monitor.c:35:
/usr/include/inttypes.h:104:19: note: format string is defined here
  104 | # define PRIu32  "u"
Copy link
Member

@ArsenArsen ArsenArsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what an ugly issue, the fix seems reasonable (AFAIK 64 bit arithmetic isn't a problem on any CPUs, so this cast shouldn't be that problematic, so unless someone knows more about non-amd64 cpus, this seems alright)

@bbonev bbonev merged commit 91066e4 into eudev-project:master Jun 12, 2022
@bbonev bbonev deleted the time32warn branch June 12, 2022 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants